<template>
  <!-- 预约信息---就诊 ---唐莉 -->
  <el-dialog title="编辑预约信息" :visible="value" width="700px" custom-class="dialog-box" @close="onClose" @open="onOpen" :close-on-click-modal="false" :append-to-body="true">
    <el-form ref="form" :model="form" :rules="rules" label-width="140px" @submit.native.prevent="onSubmit">
      <el-row>
        <el-col :span="24">
          <el-form-item label="预约内容：">
            <el-input v-model="form.registerContent" type="textarea"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-button v-show="false" :loading="btnLoading" native-type="submit">提交</el-button>
    </el-form>
    <span slot="footer">
      <el-button type="primary" :loading="btnLoading" @click="onSubmit">确 定</el-button>
    </span>
  </el-dialog>
</template>
<script>
export default {
  props: ["value", "curItem", "patientId"],
  data() {
    return {
      form: {
        registerContent: "",
        patientId: "",
        id: ""
      },
      suagrId: 0,
      itemList: [],
      rules: {},
      btnLoading: false
    };
  },
  created() {
    let th = this;
    th.onOpen();
  },
  methods: {
    onClose() {
      let th = this;
      th.$refs["form"].resetFields();
      th.$emit("input", false);
    },
    onOpen() {
      let th = this;
      let list;
      th.$nextTick(function() {
        if (th.curItem) {
          th.form.id = th.curItem.id;
          th.form.hpId = th.adminUser.hpId;
          th.form.registerContent = th.curItem.registerContent;
        }
      });
    },
    onSubmit() {
      let th = this;
      let j = {};
      Object.assign(j, th.form);
      th.$api
        .updateRegisterRecord(j)
        .then(res => {
          if (res.executed) {
            th.$message.success("保存成功");
            th.$emit("success");
            th.onClose();
            th.btnLoading = false;
          } else {
            th.$message.error(res.message);
            th.btnLoading = false;
          }
        })
        .catch(error => {
          th.btnLoading = false;
        });
    }
  }
};
</script>
<style lang="scss" scoped>
.btn_sign_option {
  padding: 10px;
}
.sugar_date {
  width: 30% !important;
  margin-right: 2%;
}
.sugar_select {
  width: 15%;
  margin-right: 2%;
}
.sugar_input {
  width: 40%;
}
</style>